﻿define(['services/logger', 'services/calculator'], function (logger, calculator) {
    var title = 'Subnet Calculator';
    var vm = {
        activate: activate,
        title: title,
        generate: generate,
        reset: reset,
        save: save,
        objects: ko.observableArray([])
    };

    return vm;

    //#region Internal Methods
    function activate() {
        logger.log(title + ' View Activated', null, title, true);
        return true;
    }

    function generate() {
        //calculator.generateSubnet(vm.objects);
        var address = $('#txtNetwork').val();
        var netbits = $('#txtMask').val();
        var result = calculator.updateNetwork(address, netbits);
        if (result === null) {
            return false;
        }
        var row = '<tr class="info"><td>' + result.address + '</td><td>' + result.netmask + '</td><td>' + result.range + '</td><td>' + result.useableips + '</td><td>' + result.hosts + '</td></tr>'
        $('#calcbody').append(row);
        return false;
    }

    function save() {
        calculator.addNetwork();
    }

    function reset() {
        //var teste = calculator.updateNetwork('', '');
        //alert(teste);
        //logger.log(result, null, title, true);
        $('#calcbody').empty();
        return false;
    }
    //#endregion
});